package com.mkvld.appietijdenv2;

import android.app.AlertDialog;
import android.content.DialogInterface;

import com.mkvld.appietijdenv2.R;
import com.mkvld.appietijdenv2.activities.ActMainV9;
import com.mkvld.appietijdenv2.data.Shift;
import com.mkvld.appietijdenv2.data.Shift.ShiftType;
import com.mkvld.appietijdenv2.databases.ShiftDatabase;
import com.mkvld.appietijdenv2.dialogs.DialNewShiftV9;
import com.mkvld.appietijdenv2.fragments.FragShiftsV9;
import com.mkvld.appietijdenv2.views.ViewShift;

public class FragShiftsGB extends FragShiftsV9 {

	@Override
	public void shiftSelected(final ViewShift vs) {
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setItems(R.array.fs_contextitems, new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int item) {
				switch (item) {
				case 0: // add
					DialNewShiftV9.showNew(new DialNewShiftV9(), getActivity(), getYear(), getPeriod() * 4 + vs.getWeek(), vs.getDay());
					break;
				case 1: // edit
					DialNewShiftV9.showEdit(new DialNewShiftV9(), getActivity(), new Shift(ShiftType.PRODUCTIVE, getYear(), getPeriod() * 4 + vs.getWeek(), vs.getDay(), vs.getStart(), vs.getEnd(), -1));
					break;
				case 2: // remove
					ShiftDatabase.db.deleteShift(new Shift(ShiftType.PRODUCTIVE, getYear(), getPeriod() * 4 + vs.getWeek(), vs.getDay(), vs.getStart(), vs.getEnd(), -1));
					((ActMainV9)getActivity()).update();
					break;

				default:
					break;
				}
			}
		});
		builder.show();
	}

}
